package com.basic.boot.web.controller;

import com.basic.boot.common.reqlimit.AnRateLimiter;
import com.basic.boot.exception.NoAuthException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @author cherrish
 * @time 2019-03-13 17:41
 * @name WelcomeController
 * @desc:
 */
@Controller
public class WelcomeController {
    @GetMapping("/welcome")
    @ResponseBody
    public String welcome(){
        return "Welcome to web-boot: " + new Date();
    }

    @RequestMapping(value = "/views/welcome")
    public String welcome(Integer no){
        return "welcome";
    }

    @RequestMapping(value = "/views/auth")
    public void auth(){
        throw new NoAuthException("No auth");
    }

    @AnRateLimiter(permitsPerSecond = 1, timeOut = 20)
    @GetMapping(value = "/api/limit/{no}")
    @ResponseBody
    public String limit(@PathVariable Integer no){
        return "Request limit test";
    }
}
